package zhieasy.cn.service.initiation.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zhieasy.cn.model.common.CollegeInfo;
import zhieasy.cn.model.common.Grade;
import zhieasy.cn.model.common.Major;
import zhieasy.cn.persistence.mapper.common.CollegeInfoMapper;
import zhieasy.cn.persistence.mapper.common.GradeMapper;
import zhieasy.cn.persistence.mapper.common.MajorMapper;
import zhieasy.cn.service.initiation.CollegeInfoService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sofency
 * @date 2020/8/22 0:20
 * @package IntelliJ IDEA
 * @description
 */
@Service
public class CollegeInfoServiceImpl  implements CollegeInfoService {

    @Autowired
    CollegeInfoMapper collegeInfoMapper;

    @Autowired
    MajorMapper majorMapper;

    @Autowired
    GradeMapper gradeMapper;
    /**
     * 获取到所有的学院
     * @return
     */
    @Override
    public List<CollegeInfo> getColleges() {
        List<CollegeInfo> collegeInfos = collegeInfoMapper.selectByMap(null);
        return collegeInfos;
    }

    /**
     * 根据学院的id获取专业列表
     * @param collegeId
     * @return
     */
    @Override
    public List<Major> getMajors(String collegeId) {
        Map<String,Object> map = new HashMap<>();
        map.put("college_id",collegeId);
        return majorMapper.selectByMap(map);
    }

    @Override
    public List<Grade> getGrades(String collegeId, String majorId) {
        Map<String,Object> map  = new HashMap<>();
        map.put("college_id",collegeId);
        map.put("major_id",majorId);
        List<Grade> grades = gradeMapper.selectByMap(map);
        return grades;
    }
}
